/*业务逻辑(左侧加号展开阅读):
 * 商家数据更新程序
 * 1. 获取前台jsp页面用户输入的信息
 * 2. 判断用户两次密码输入是否一致
 * 3. 将用户输入的数据封装至Boss对象中
 * 4. 将数据上传至数据库
 */

package OSMS.action.Boss;

import java.io.IOException;



import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import com.sun.xml.internal.ws.resources.HttpserverMessages;

import OSMS.entity.*;
import OSMS.dao.*;

public class Boss_Update_Servlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try{
//------------------1.获取信息页面的数据----------------------//
			request.setCharacterEncoding("UTF-8");
//			response.setCharacterEncoding("UTF-8");
//			response.setContentType("text/html;charset=utf-8");
			
			
			HttpSession session = request.getSession();
			Object obj_user = session.getAttribute("boss");//从LoginServlet中获取user值
			Boss bos = (Boss) obj_user;
			Object id = bos.getBid();
			int bid = Integer.parseInt(id.toString());
			
		
			
//			String id = request.getParameter("bid");
//			int bid = 0 ;
//			bid = Integer.parseInt(id.toString());
//			System.out.println("打印bid："+bid);
			
//			String bname = request.getParameter("bname");
//			System.out.println("打印bname："+bname);
//			String btel = request.getParameter("btel");
//			System.out.println("打印btel："+btel);
			String baddress = request.getParameter("baddress");
//			System.out.println("打印baddress："+baddress);

			String bpwd = request.getParameter("bpwd");
//			System.out.println("打印第一次输入密码："+bpwd);
			String bpwd_assure = request.getParameter("bpwd_a");
//			System.out.println("打印第二次输入密码："+bpwd_assure);
			
//------------------2.验证两次密码是否正确--------------------//
			if(!bpwd.equals(bpwd_assure))
			{
				request.getRequestDispatcher("updateboss.jsp").forward(request, response);
			}
//------------------3.封装前台数据---------------------------//
			Boss boss = new Boss();
//			HttpSession session = request.getSession();
//			boss = (Boss) session.getAttribute("boss");
//			
			boss.setBid(bid);
//			boss.setBname(bname);
//			boss.setBtel(btel);
			boss.setBaddress(baddress);
			boss.setBpwd(bpwd);


//------------------4.上传至数据库--------------------------//
			BossDao bdao = new BossDao();
			boolean flag = false;
			flag = bdao.updateBoss(boss);
			System.out.println("打印修改结果："+flag);
			if(flag){
				request.getRequestDispatcher("bosslogin.html").forward(request, response);
			}else{
				
				System.out.println("不成啊");
			}

		}catch(Exception ex){
			ex.printStackTrace();
		}
		
		
	}
	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
	
	
	
}